home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48_1 / brief.mac < prev    next >
Lisp/Scheme  |  1995-03-23  |  9KB  |  165 lines

  1. Article 5632 of comp.sys.handhelds:
  2. Path: en.ecn.purdue.edu!noose.ecn.purdue.edu!samsung!usc!zaphod.mps.ohio-state.edu!casbah.acns.nwu.edu!ucsd!qualcom.qualcomm.com!williams
  3. From: williams@qualcomm.com (Paul Williamson)
  4. Newsgroups: comp.sys.handhelds
  5. Subject: HP48 Download macro for BRIEF
  6. Keywords: HP48 BRIEF Kermit download lazy
  7. Message-ID: <1991Apr6.150005.7449@qualcomm.com>
  8. Date: 6 Apr 91 15:00:05 GMT
  9. Organization: Qualcomm Inc., San Diego, CA
  10. Lines: 151
  11.  
  12.  
  13. /*************************************************************************\
  14. *                                                                         *
  15. * HP-48SX Kermit Interface for BRIEF                                      *
  16. *                                                                         *
  17. * Copyright 1991 Paul Williamson, KB5MU; All Rights Reserved              *
  18. * You may use this program for non-commercial purposes.                   *
  19. * You may distribute copies, as long as no fee is charged and any         *
  20. * modifications you make are clearly marked.                              *
  21. *                                                                         *
  22. * This file is written in CBRIEF, the C-like macro language used          *
  23. * to customize BRIEF, a program editor.  I used BRIEF version 3.10        *
  24. * to write and debug it.                                                  *
  25. *                                                                         *
  26. * It defines a single macro, kermit_download.  If you invoke the macro    *
  27. * from inside a file containing an HP-48SX downloadable object (of any    *
  28. * flavor), the file will be written out to disk (if necessary) and        *
  29. * downloaded to your calculator immediately.  You don't have to leave     *
  30. * the editor!  If you have a region of text within the file selected      *
  31. * when you invoke kermit_download, the macro assumes that you want to     *
  32. * use just the marked region as an HP-48SX object.  It will ask you for   *
  33. * two names: one for the HP-48SX, and one for the PC.  You will probably  *
  34. * want to accept the default PC name, which is just the HP-48SX name.     *
  35. * The macro will then write the region to the PC file you specify, and    *
  36. * download it to the HP-48SX file you specify.                            *
  37. *                                                                         *
  38. * The macro calls the regular Kermit program.  I tested with the version  *
  39. * that calls itself "IBM-PC MS-DOS Kermit: 3.10 13 March 1991", from      *
  40. * Columbia University.  This program must be on your DOS PATH somewhere.  *
  41. * The macro also assumes that a special Kermit initialization file,       *
  42. * named KERMHP48.INI, is somewhere on your path.  This file contains      *
  43. * Kermit commands to configure Kermit's parameters to match the HP-48SX.  *
  44. * My  KERMHP48.INI looks like this:                                       *
  45. *       ;; configuration for talking to HP48SX                            *
  46. *       set remote on                                                     *
  47. *       set port 4                                                        *
  48. *       set speed 9600                                                    *
  49. *       pause 0         X  ; why do I need this?                                *
  50. *                                                                         *
  51. * When I download a file containing HP-48SX code, I always name it with   *
  52. * an extension of ".48".  BRIEF can key on the file extension and load    *
  53. * this macro automatically, so you'll always have one-keystroke Kermit    *
  54. * transfers available from inside the editor.  Just add this to your      *
  55. * initials macro:                                                         *
  56. *     (macro .48                                                          *
  57. *        (                                                                *
  58. *           (autoload "hp48" "kermit_download")                           *
  59. *           (keyboard_push)                                               *
  60. *           (assign_to_key "<Ctrl-d>" "kermit_download")                  *
  61. *           (use_local_keyboard (inq_keyboard))                           *
  62. *           (keyboard_pop 1)                                              *
  63. *        )                                                                *
  64. *     )                                                                   *
  65. * Assuming that you name this file HP48.CB, and compile it using CB, and  *
  66. * place the resulting HP48.CM file in your MACROS directory, this will    *
  67. * automatically set you up.  The assign_to_key command above assigns      *
  68. * this macro to Ctrl-D (for download).  You can, of course, assign it to  *
  69. * whatever key suits your fancy.                                          *
  70. *                                                                         *
  71. * I'd appreciate any comments you may have.  Bug reports are always       *
  72. * welcome, but of course I can't promise to do anything about them.       *
  73. *                                                                         *
  74. * Paul Williamson, KB5MU                                                  *
  75. * Internet: pwilliamson@drzeus.qualcomm.com                               *
  76. * Compu$erve: 75265,367                                                   *
  77. *                                                                         *
  78. \*************************************************************************/
  79.  
  80. int kermit_download()
  81. {
  82.    string   command;             // command to send to kermit
  83.    string   pc_fn;               // name of the current file on the PC
  84.    string   hp_fn;               // name of the object to be sent to HP48
  85.    int      ret_val;             // return value from Kermit
  86.    int      old_msg_level = inq_msg_level();
  87.  
  88.    if (inq_marked())             // check to see if a region is marked
  89.       {                          // If it is, we need to make a file of it.
  90.       int      buf_id;
  91.       int      old_buf = inq_buffer();       // save current buffer ID
  92.  
  93.       if (!get_parm(NULL, hp_fn, "HP48SX Name: "))
  94.          return (-1);            // don't do anything if he won't answer
  95.       if (!strlen(hp_fn))
  96.          return(-1);             // or if he didn't give us a name.
  97.       if (!get_parm(NULL, pc_fn, "PC filename: ", NULL, hp_fn))
  98.          return(-1);             // same here.
  99.       if (!strlen(pc_fn))
  100.          return(-1);             // and here.
  101.  
  102.       buf_id = create_buffer("temp file", pc_fn, 1); // make a system buffer
  103.       if (!buf_id)               // and make sure that worked.
  104.          {
  105.          error("%s is not a valid filename.");
  106.          beep();
  107.          return(-2);
  108.          }
  109.  
  110.       /* I'd like to use transfer() here, so as not to stomp the scrap,
  111.          but transfer doesn't grok column-marks.  I decided that copying
  112.          by columns was more important than preserving the scrap. */
  113.  
  114.       copy();                    // copy marked region to scrap
  115.       set_buffer(buf_id);
  116.       paste();                   // and stick it in our system buffer
  117.  
  118.       set_msg_level(0);          // (let write error messages show thru)
  119.       if (write_buffer() <= 0)   // write the good stuff out to a file
  120.          {                       // making sure it worked.
  121.          error("Couldn't write file %s.", pc_fn);
  122.          beep();
  123.          set_msg_level(old_msg_level);
  124.          return (-2);
  125.          }
  126.  
  127.       set_msg_level(old_msg_level);
  128.       set_buffer(old_buf);             // and clean up the garbage
  129.       delete_buffer(buf_id);     
  130.       }
  131.    else  // there was no region marked, so we can deal with the whole file
  132.       {
  133.       inq_names(pc_fn, NULL, hp_fn);   // get the name of the current file
  134.                                        // pc_fn gets full path
  135.       if (inq_modified())              // hp_fn gets just the filename
  136.          {
  137.          message("Writing %s...", pc_fn); // write it out if it's dirty
  138.          set_msg_level(0);
  139.          write_buffer();
  140.          set_msg_level(old_msg_level);
  141.          }
  142.       }
  143.  
  144.    sprintf(command, "kermit -f kermhp48.ini send %s %s >&NUL",
  145.                pc_fn, hp_fn);       // the command to download the file
  146.                                     // KERMHP48.INI contains the parameters
  147.    message("Running Kermit...");    // Keep the user informed.
  148.    ret_val = dos(command, 0);       // Finally, run Kermit.
  149.    switch (ret_val)                 // and let the user know what happened.
  150.       {
  151.       case 0:
  152.          message("File transmitted OK.");
  153.       case 1:
  154.          error("File send failed!");
  155.          beep();
  156.       default:                      // No other error code should happen,
  157.          error("Error code %d", ret_val); // but handle it anyway.
  158.          beep();
  159.       }
  160.    return (ret_val);                // pass status back up, for other macros
  161. }
  162. /* end of kermit_download */
  163.  
  164.  
  165.